def solve(s):
    n = len(s)
    res = 0

    roman_dict = {
        "I": 1,
        "V": 5,
        "X": 10,
        "L": 50,
        "C": 100,
        "D": 500,
        "M": 1000
    }

    for i in range(n):
        if i < n - 1:
            num1 = roman_dict[s[i]]
            num2 = roman_dict[s[i + 1]]
            if num1 < num2:
                res -= num1
            else:
                res += num1
        else:
            res += roman_dict[s[i]]

    return res


if __name__ == "__main__":
    s = "IX"
    print(solve(s))
